log using figures_main_pop, replace
cd  "\\micro.intra\Projekt\P0624$\P0624_Gem\Kitschelt\submission"
use main_data_pop, replace

***Figure 3
preserve
gen ssyk96 =substr(ssyk96kod, 1, 3)
gen occup_gr="Social Worker" if Ssyk4=="2492" 	& sector<0
replace	 occup_gr="Nurse" if (ssyk96=="223" | ssyk96=="323"	)	 	& sector<0				
replace	 occup_gr="Police" if Ssyk4=="3450"   	& sector<0
replace occup_gr="CEO" if  ssyk96=="121"& sector==1
replace	 occup_gr="Machine Operator" if ssyk96=="821" | ssyk96=="822" | ssyk96=="823" | ssyk96=="824" | ssyk96=="825" | ssyk96=="826" | ssyk96=="827" 
replace	 occup_gr="Farmer" if (ssyk96=="621" | ssyk96=="622"	| ssyk96=="623" | ssyk96=="624")
replace	 occup_gr="Indep. Craftsman" if (ssyk96=="712" | ssyk96=="713"	| ssyk96=="714" ) & cap_exec>.5
replace	 occup_gr="Vehicle Driver" if (ssyk96=="832") 
keep if occup_gr!=""
keep if  y!=. & x!=.
collapse y  x, by(occup_gr)
save mean_y_x_occ, replace
restore
preserve
gen count=1
keep if  y!=. & x!=.
foreach var in x  y {
	gen gr_`var'_50=(int(25*				(`var'+0.0000001))-0.5)/25 if `var'<0
	replace gr_`var'_50=(int(25*(`var'-0.0000001))+0.5)/25  if `var'>=0
}
collapse(sum) count, by(gr_y_50 gr_x_50)
egen pop_count=sum(count)
gen share= count/pop_count
append using mean_y_x_occ

twoway (scatter gr_y gr_x [fweight = share]  , mcolor(gs12)  mlwidth(thin) msymbol(circle) mfcolor(none) msize(small)) ///
	(scatter y x if occup_gr!="",  msize(medium) mlabel(occup_gr) mlabsize(medium) msymbol(circle) mlabposition(3) mcolor(black) mlabcolor(black)) ///
	, scheme(s1color) xline(0) yline(0) title(Population) ytitle(Libertarian - Authoritarian) xtitle(Left-Right) legend(off) ysize(5) xsize(5.5)
graph save Figure_3, replace
restore 

***Prepare for PCA-analyses
gen sex=1 if Kon==2
replace sex=-1 if Kon==1
global lablist education  sex    ConcOther AssCareOther NegConSolv ServOriCare SocPercep ///
	ConMacProc_ DocRecInfo_ HandMoveObj_ InterComp_ AdminAct_ ///
	stdoffshore_pct  /// 
	PrivSec-NonProfit inc_pct  busink OpFtgLedare BusPers 
pca $lablist
screeplot , yline(1)
graph save screeplot, replace
estat loadings
estat kmo 
predict pc1 pc2 pc3 , score
**Figure W7
foreach ind in x y{
	foreach pc in pc1 pc2 pc3{
		binscatter `ind' `pc', nq(100)
		graph save `ind'_`pc', replace
	}
}
 graph combine y_pc1.gph x_pc1.gph y_pc2.gph x_pc2.gph y_pc3.gph x_pc3.gph, ///
	ycommon  iscale(.5) row(3) col(2) ysize(20) xsize(20) scheme(s1mono)
 graph save W7, replace
 log close